package org.jsping.dao.impl;

import java.sql.ResultSet;

import org.jsping.dao.ICollectionDao;

public class CollectionDaoImpl extends BaseDao implements ICollectionDao{

	/*添加 新的  record*/
	@Override
	public int addRecord(int uid, int mid) {
		int result = 0;
		System.out.println(result);
		try {
			//添加
			String sql = "INSERT INTO collection VALUES(DEFAULT,?,?);";
			result = this.executeUpdate(sql, uid,String.valueOf(mid));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/*更新信息*/
	@Override
	public int updateRecord(int uid, String record) {
		int result = 0;
		try {
			//获取  record 
			String sql = "UPDATE collection SET records = ? WHERE uid = ?";
			//更新
			result = this.executeUpdate(sql, record,uid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/*获取record*/
	@Override
	public String getRecord(int uid) {
		String src = "";
		try {
				String sql = "SELECT records FROM collection WHERE uid=?";
				rs = this.executeQuery(sql, uid);
				while(rs.next()){
					src = rs.getString("records");
				}
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			this.releaseAll();
		}
		return src;
	}

	/*用户是否存在*/
	@Override
	public ResultSet isExists(int uid) {
		try {
			String sql = "SELECT * FROM `collection` WHERE uid=?";
			rs = executeQuery(sql, uid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return rs;
	}

}
